﻿//#define BREAK_ON_ASSERT_FAIL

using System;

namespace HappyTemplate
{
	[Serializable]
	public class AssertException : Exception
	{
		public AssertException() { }
		public AssertException(string message) : base(message) { }
		public AssertException(string message, Exception inner) : base(message, inner) { }
		public AssertException(string msg, params object[] args)
			: base(StringHelp.Format(msg, args)) { }
	}
	static class DebugAssert
	{
		private static void FailAssertion(string msg, params object[] args)
		{
#if BREAK_ON_ASSERT_FAIL
			System.Diagnostics.Debugger.Break();
#endif
			throw new AssertException(msg, args);
		}

		private static void FailAssertion()
		{
#if BREAK_ON_ASSERT_FAIL
			System.Diagnostics.Debugger.Break();
#endif
			throw new AssertException();
		}
		public static void IsNotNull(object o)
		{
			if (o == null)
				FailAssertion();
		}
		public static void IsNull(object o, string msg, params object[] args)
		{
			if (o != null)
				FailAssertion(msg, args);
		}
		public static void IsNotNull(object o, string msg, params object[] args)
		{
			if (o == null)
				FailAssertion(msg, args);
		}
		public static void IsInstanceOfType(Type t, object o)
		{
			Type was = o.GetType();
			if(!t.Equals(was))
				FailAssertion(StringHelp.Format("UserType expected:  '{0}' but was '{1}'", t.Name, was.Name));
		}

		public static void AreNotEqual(object a, object b, string fmt, params object[] args)
		{
			if (a.Equals(b))
				FailAssertion(StringHelp.Format(fmt, args));
		}
		public static void AreEqual(object a, object b, string fmt, params object[] args)
		{
			if (!a.Equals(b))
				FailAssertion(StringHelp.Format(fmt, args));
		}
		public static void IsTrue(bool val, string fmt, params object[] args)
		{
			if(val != true)
				FailAssertion(StringHelp.Format(fmt, args));
			
		}
		public static void IsFalse(bool val, string fmt, params object[] args)
		{
			if (val != false)
				FailAssertion(StringHelp.Format(fmt, args));

		}
		public static void IsGreater(int less, int greater, string fmt, params object[] args)
		{
			if (greater <= less)
				FailAssertion(StringHelp.Format(fmt, args));

		}

	}
}
